{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#  WSTP vs WolframLibrary Simple Speed Benchmark"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><img alt=\"Output\" src=\"\"></div>"
      ],
      "text/plain": [
       "LinkObject['/home/yangyongkang/文档/C-CPP_WolframLibrary_Example/Example_Benchmark/WSTP_Be\\\n",
       " \n",
       ">    nchmark/WSTP_PutInteger', 259, 3]"
      ]
     },
     "execution_count": 3,
     "metadata": {
      "text/html": [],
      "text/plain": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "link=Install[\"/home/yangyongkang/文档/C-CPP_WolframLibrary_Example/Example_Benchmark/WSTP_Ben\n",
    "chmark/WSTP_PutInteger\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><img alt=\"Output\" src=\"\"></div>"
      ],
      "text/plain": [
       "LinkObject['/home/yangyongkang/文档/C-CPP_WolframLibrary_Example/Example_Benchmark/WSTP_Be\\\n",
       " \n",
       ">    nchmark/WSTP_PutIntegerList', 285, 4]"
      ]
     },
     "execution_count": 4,
     "metadata": {
      "text/html": [],
      "text/plain": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "link1=Install[\"/home/yangyongkang/文档/C-CPP_WolframLibrary_Example/Example_Benchmark/WSTP_Ben\n",
    "chmark/WSTP_PutIntegerList\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><img alt=\"Output\" src=\"\"></div>"
      ],
      "text/plain": [
       "LibraryFunction[<>, PutInteger, {Integer}, Integer]"
      ]
     },
     "execution_count": 6,
     "metadata": {
      "text/html": [],
      "text/plain": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "PutInteger=LibraryFunctionLoad[\"/home/yangyongkang/文档/C-CPP_WolframLibrary_Example/Example_Benchmark/WolframL\n",
    "ibrary_Benchmark/WolframLibrary_Benchmark.so\",\"PutInteger\",{Integer},Integer]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><img alt=\"Output\" src=\"\"></div>"
      ],
      "text/plain": [
       "LibraryFunction[<>, PutIntegerList, {Integer}, {Integer, 1}]"
      ]
     },
     "execution_count": 1,
     "metadata": {
      "text/html": [],
      "text/plain": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "PutIntegerList=LibraryFunctionLoad[\"/home/yangyongkang/文档/C-CPP_WolframLibrary_Example/Example_Benchmark/WolframL\n",
    "ibrary_Benchmark/WolframLibrary_Benchmark.so\",\"PutIntegerList\",{Integer},{Integer,1}]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Put a Integer to Wolfram "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><pre style=\"&#102;&#111;&#110;&#116;&#45;&#102;&#97;&#109;&#105;&#108;&#121;&#58;&#32;&#34;&#67;&#111;&#117;&#114;&#105;&#101;&#114;&#32;&#78;&#101;&#119;&#34;&#44;&#67;&#111;&#117;&#114;&#105;&#101;&#114;&#44;&#109;&#111;&#110;&#111;&#115;&#112;&#97;&#99;&#101;&#59;\">&#123;&#48;&#46;&#48;&#48;&#48;&#53;&#53;&#44;&#32;&#48;&#46;&#48;&#48;&#50;&#53;&#48;&#51;&#44;&#32;&#48;&#46;&#48;&#53;&#48;&#57;&#55;&#54;&#44;&#32;&#48;&#46;&#51;&#49;&#56;&#50;&#55;&#125;</pre></div>"
      ],
      "text/plain": [
       "{0.00055, 0.002503, 0.050976, 0.31827}"
      ]
     },
     "execution_count": 19,
     "metadata": {
      "text/html": [],
      "text/plain": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time1=Table[Do[WSTPPutInteger[1],10^k]//AbsoluteTiming,{k,1,4}][[All,1]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><pre style=\"&#102;&#111;&#110;&#116;&#45;&#102;&#97;&#109;&#105;&#108;&#121;&#58;&#32;&#34;&#67;&#111;&#117;&#114;&#105;&#101;&#114;&#32;&#78;&#101;&#119;&#34;&#44;&#67;&#111;&#117;&#114;&#105;&#101;&#114;&#44;&#109;&#111;&#110;&#111;&#115;&#112;&#97;&#99;&#101;&#59;\">&#123;&#48;&#46;&#48;&#48;&#48;&#48;&#49;&#55;&#44;&#32;&#48;&#46;&#48;&#48;&#48;&#48;&#52;&#53;&#44;&#32;&#48;&#46;&#48;&#48;&#48;&#52;&#49;&#54;&#44;&#32;&#48;&#46;&#48;&#48;&#51;&#53;&#57;&#51;&#125;</pre></div>"
      ],
      "text/plain": [
       "{0.000017, 0.000045, 0.000416, 0.003593}"
      ]
     },
     "execution_count": 20,
     "metadata": {
      "text/html": [],
      "text/plain": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time2=Table[Do[PutInteger[1],10^k]//AbsoluteTiming,{k,1,4}][[All,1]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><img alt=\"Output\" src=\"\"></div>"
      ],
      "text/plain": [
       "                                                             7\n",
       "Legended[-Graphics-, Placed[LineLegend[{Directive[PointSize[---], \n",
       "                                                            360\n",
       " \n",
       ">       RGBColor[0.368417, 0.506779, 0.709798], AbsoluteThickness[1.6]], \n",
       " \n",
       "                            7\n",
       ">      Directive[PointSize[---], RGBColor[0.880722, 0.611041, 0.142051], \n",
       "                           360\n",
       " \n",
       ">       AbsoluteThickness[1.6]]}, {WSTP, WolframLibary}, \n",
       " \n",
       ">     LegendMarkers -> {{False, Automatic}, {False, Automatic}}, Joined -> {True, True}, \n",
       " \n",
       ">     LabelStyle -> {}, LegendLayout -> Column], After, Identity]]"
      ]
     },
     "execution_count": 26,
     "metadata": {
      "text/html": [],
      "text/plain": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ListLinePlot[{time1,time2},PlotLegends->{\"WSTP\",\"WolframLibary\"},AxesLabel->{\"n\",\"time/s\"}]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Put a IntegerList to Wolfram"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "time3=Table[Do[WSTPPutIntegerList[10],10*k]//AbsoluteTiming,{k,1,100}][[All,1]];"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "time4=Table[Do[PutIntegerList[10],10*k]//AbsoluteTiming,{k,1,100}][[All,1]];"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><img alt=\"Output\" src=\"\"></div>"
      ],
      "text/plain": [
       "                                                            1\n",
       "Legended[-Graphics-, Placed[LineLegend[{Directive[PointSize[--], \n",
       "                                                            72\n",
       " \n",
       ">       RGBColor[0.368417, 0.506779, 0.709798], AbsoluteThickness[1.6]], \n",
       " \n",
       "                           1\n",
       ">      Directive[PointSize[--], RGBColor[0.880722, 0.611041, 0.142051], \n",
       "                           72\n",
       " \n",
       ">       AbsoluteThickness[1.6]]}, {WSTP, WolframLibary}, \n",
       " \n",
       ">     LegendMarkers -> {{False, Automatic}, {False, Automatic}}, Joined -> {True, True}, \n",
       " \n",
       ">     LabelStyle -> {}, LegendLayout -> Column], After, Identity]]"
      ]
     },
     "execution_count": 18,
     "metadata": {
      "text/html": [],
      "text/plain": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ListLinePlot[{time3,time4},PlotLegends->{\"WSTP\",\"WolframLibary\"},AxesLabel->{\"n\",\"time/s\"}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Wolfram Language 12.1",
   "language": "Wolfram Language",
   "name": "wolframlanguage12.1"
  },
  "language_info": {
   "codemirror_mode": "mathematica",
   "file_extension": ".m",
   "mimetype": "application/vnd.wolfram.m",
   "name": "Wolfram Language",
   "pygments_lexer": "mathematica",
   "version": "12.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
